package com.zjsru.dailytest;

/**
 * @Author: likew
 * @Date: 2022/2/22
 *
 * 2的幂
 *
 * 输入：n = 1
 * 输出：true
 * 解释：2的0次方 = 1
 *
 * 输入：n = 3
 * 输出：false
 */
public class isPowerOf2 {
    public boolean isPowerOfTwo(int n) {
        if(n < 1){
            return false;
        }
        while(n % 2 == 0){
            n /= 2;
        }
        return n == 1;
    }

    public static void main(String[] args) {
        isPowerOf2 isPowerOf2 = new isPowerOf2();
        int n = 1;
        System.out.println(isPowerOf2.isPowerOfTwo(n));
    }
}
